#include <stdio.h>
#include <stdlib.h>

typedef int HElemSet;
typedef int Position; /* 数组下标即为元素位置 */
typedef struct BinaryHeapNode *MinHeap;
struct BinaryHeapNode {
    HElemSet *data; /* 数据元素数组 */
    int size; /* 规模 */
    int capacity; /* 容量 */
};

void InitPQueue(MinHeap pq, int capacity);
void SiftUp(MinHeap h, Position i);
void Insert(MinHeap h, HElemSet x);

void Solve(int n, int m) {
    MinHeap h;
    int i, j;
    HElemSet x;

    /* 初始化最小堆 */
    h = (MinHeap)malloc(sizeof(struct BinaryHeapNode));
    InitPQueue(h, n);
    /* 读入数据并插入堆 */
    for (i = 0; i < n; i++) {
        scanf("%d", &x);
        Insert(h, x);
    }
    /* 读入数据下标并打印路径 */
    for (j = 0; j < m; j++) {
        scanf("%d", &i);
        printf("%d", h->data[i]); /* 输出起点 */
        for (i >>= 1; i > 0; i >>= 1) { /* 顺次访问父结点 */
            printf(" %d", h->data[i]);
        }
        printf("\n");
    }
}

int main(void) {
    int n, m;

    scanf("%d %d", &n, &m);
    Solve(n, m);

    return 0;
}

void InitPQueue(MinHeap pq, int capacity) {
    pq->capacity = capacity;
    pq->size = 0;
    /* 数据从下标1开始存储，需要多声明1个空间 */
    pq->data = (HElemSet *)malloc(sizeof(HElemSet) * (capacity + 1));
}

void SiftUp(MinHeap h, Position i) {
    HElemSet elem;

    elem = h->data[i];
    while (i > 1 && elem < h->data[i >> 1]) { /* 当前结点小于其父结点 */
        h->data[i] = h->data[i >> 1]; /* 将i的父结点元素下移 */
        i >>= 1; /* i指向原结点的父结点，即向上调整 */
    }
    h->data[i] = elem;
}

void Insert(MinHeap h, HElemSet x) {
    Position last;

    if (h->size == h->capacity) { /* 堆已满 */
        printf("错误：堆已满，无法插入。\n");
    } else {
        h->size++;
        last = h->size;
        h->data[last] = x; /* 暂时将x放入最后一个元素的位置 */
        SiftUp(h, last);
    }
}